const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    bg1 = null;
    bg2 = null;
    cur_bg = null;
    speed = 200;
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.bg1 = this.node.getChildByName('repeat_bg1');
        this.bg2 = this.node.getChildByName('repeat_bg2');
        this.cur_bg = this.bg1;
    }

    start () {

    }

    update (dt) {
        var s = dt * this.speed;
        this.bg1.x -= s;
        this.bg2.x -= s;
        if (this.cur_bg.x <= -1024) { // 地图切换
            if(this.cur_bg == this.bg2) {
                this.bg2.x = this.bg1.x + 1024;
                this.cur_bg = this.bg1;
            }
            else {
                this.bg1.x = this.bg2.x + 1024;
                this.cur_bg = this.bg2;
            }
        }
    }
}
